package com.spirng.leetcode.uitl;

import java.util.concurrent.*;

public class ExecuteExample {
    public void test() throws Exception{
        int i=1/0;
    }
    public static void main(String[] args) throws Exception {
        ExecutorService executorService = Executors.newFixedThreadPool(10);
        Runnable task=() ->{
            System.out.println("Runnable运行的线程是"+Thread.currentThread().getName());
            throw new RuntimeException("Runnableyuanixngyichang");
        };
        Callable<String> callableTask=() -> {
            System.out.println("callable运行的线程是"+Thread.currentThread().getName());
            int i=1/0;
            System.out.println("===");
            return "sdada";
        };

//        Future<?> future = executorService.submit(task);//Runnable类型的任务没有返回值
        try {
            Future<String> future1 = executorService.submit(callableTask);
//            String s = future1.get();
//            System.out.println("s="+s);
            executorService.execute(task);
        } catch (Exception e) {
            System.err.println("Caught exception from Future.get(): " + e.getMessage());
            if (e.getCause() instanceof RuntimeException) {
                e.getCause().printStackTrace();
            }
        }
        executorService.shutdown();
    }
}
